const { app, BrowserWindow } = require('electron')
const path = require('path')
const createServer = require('./backend.js')
var isDev = process.env.IS_DEV == 'true' ? true : false;

function createWindow() {
    const win = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
            preload: path.join(__dirname, 'preload.js')
        }


    })
    isDev
        ? win.loadURL('http://localhost:3000')
        : win.loadFile(path.join(__dirname, "../dist/index.html"))
    if (isDev) {
        win.webContents.openDevTools()
    }
}

app.whenReady().then(() => {
    createWindow()
    createServer()
    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) {
            createWindow()
        }
    })
})

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
        app.quit()
    }
})
